﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SQLServerHealthCheck.Model
{
        public enum DatabaseTraceState
        { 
            New, 
            IsRunning,
            Finished,
            Scheduled
        
        
        }
    public partial class DatabaseTrace
    {

        public string DatabaseName
        {
            get { return Database.DatabaseName; }

        }

        public DatabaseTraceState State
        {
            get 
            {

                DatabaseTraceState state = DatabaseTraceState.New;
                DateTime currentTime = DateTime.Now;

                if(this.DatabaseTraceId ==0) 
                {
                    state = DatabaseTraceState.New;
                
                }
                else if (this.DatabaseTraceId > 0 && this.TraceStart < currentTime && this.TraceEnd > currentTime)
                {

                    state = DatabaseTraceState.IsRunning;
                }
               
                else if((this.DatabaseTraceId > 0 && this.TraceEnd < currentTime))
                {
                    state = DatabaseTraceState.Finished;
                }
                else if ((this.DatabaseTraceId > 0 && this.TraceStart > currentTime))
                {
                    state = DatabaseTraceState.Scheduled;
                }
                return state; 
           }
      
        }


    }
}
